﻿using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using SHKF.B2C.JuShuiTan.Model;
using SHKF.B2C.JuShuiTan.Model.Inter.CombineSkuQuery;
using SHKF.B2C.JuShuiTan.Model.Inter.ItemskuUpload;
using SHKF.B2C.JuShuiTan.Network;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace SHKF.B2C.JuShuiTan.Service.Controllers
{
    /// <summary>
    /// 产品
    /// </summary>
    [Route("[controller]")]
    [ApiController]
    public class ProductController : BaseController
    {
  
        public ProductController(IServiceProvider serviceProvider, ILogger<ProductController> logger) : base(serviceProvider, logger)
        {

        }

        /// <summary>
        /// 上架产品
        /// </summary>
        /// <param name="data"></param>
        /// <returns></returns>
        [HttpPost("upload")]
        public async Task<BaseDto> upload(ItemSkuParam data)
        {
            BaseDto dto;
            try
            {
                BaseDto dto2 = this.GetCompanyID();
                if (dto2.code == -1)
                {
                    dto = new BaseDto();
                    dto.code = -1;
                    dto.msg = dto2.msg;

                    return dto;
                }
                else
                {
                    this.httpClient.CompanyID = dto2.msg;

                }
                dto = await this.httpClient.ItemSkuUpload(data);
            }
            catch (Exception ex)
            {
                dto = new BaseDto();
                dto.code = -1;
                dto.msg = ex.Message;
            }

            return dto;
        }


        [HttpPost("combine/query")]
        public async Task<CombineSkuQueryDto> CombineSkuQuery(CombineSkuQueryParam data)
        {
            CombineSkuQueryDto dto;
            try
            {
                BaseDto dto2 = this.GetCompanyID();
                if (dto2.code == -1)
                {
                    dto = new CombineSkuQueryDto();
                    dto.code = -1;
                    dto.msg = dto2.msg;

                    return dto;
                }
                else
                {
                    this.httpClient.CompanyID = dto2.msg;

                }
                dto = await this.httpClient.CombineSkuQuery(data);
            }
            catch (Exception ex)
            {
                dto = new CombineSkuQueryDto();
                dto.code = -1;
                dto.msg = ex.Message;
            }

            return dto;
        }

        public string Get()
        {
            return "product";
        }
    }
}
